<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
    <title>考勤</title>
    
    <link href="../css/mui.min.css" rel="stylesheet"/>
    <link href="../css/style.css" rel="stylesheet"/>
    <link href="../css/iconfont.css" rel="stylesheet"/>
</head>
<body>
<header class="mui-bar mui-bar-nav">
	<!--<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>-->
	<h1 id="title" class="mui-title">首页</h1>
</header>
<nav id="dash" class="mui-bar mui-bar-tab">
	<a id="dash_home" class="mui-tab-item mui-active" href="homepage/homepage.html"> 
		<span class="mui-icon iconfont icon-iconzhuye"></span> 
		<span class="mui-tab-label">首页</span> 
	</a>
	<a id="dash_statistic" class="mui-tab-item"  href="statistic/statistic.html"> 
		<span class="mui-icon iconfont icon-liebiao"></span> 
		<span class="mui-tab-label">考勤统计</span> 
	</a>
	<a id="dash_user" class="mui-tab-item" href="self/self.html"> 
		<span class="mui-icon iconfont icon-yonghu"></span> 
		<span class="mui-tab-label">我的</span> 
	</a>
</nav>
<script src="../js/mui.min.js"></script>
<script type="text/javascript" charset="utf-8">
	//mui初始化
	mui.init({
		statusBarBackground: '#f7f7f7',
	});
	var subpages = ['homepage/homepage.html', 'statistic/statistic.html', 'self/self.html'];
	var subpage_style = {
		top: '45px',
		bottom: '51px'
	};
	
	var aniShow = {};
	
	//创建子页面，首个选项卡页面显示，其它均隐藏；
	mui.plusReady(function() {
		var self = plus.webview.currentWebview();
		for (var i = 0; i < 3; i++) {
			var temp = {};
			var sub = plus.webview.create(subpages[i], subpages[i], subpage_style);
			if (i > 0) {
				sub.hide();
			}else{
				temp[subpages[i]] = "true";
				mui.extend(aniShow,temp);
			}
			self.append(sub);
		}
	});
	//当前激活选项
	var activeTab = subpages[0];
	var title = document.getElementById("title");
	//选项卡点击事件
	mui('.mui-bar-tab').on('tap', 'a', function(e) {
		var targetTab = this.getAttribute('href');
		if (targetTab == activeTab) {
			return;
		}
		//更换标题
		title.innerHTML = this.querySelector('.mui-tab-label').innerHTML;
		//显示目标选项卡
		//若为iOS平台或非首次显示，则直接显示
		if(mui.os.ios||aniShow[targetTab]){
			if(targetTab == "statistic/statistic.html"){
				var currentWebview = plus.webview.getWebviewById(targetTab);
				currentWebview.loadURL(targetTab);
				currentWebview.show();
			}
			plus.webview.show(targetTab);
		}else{
			//否则，使用fade-in动画，且保存变量
			var temp = {};
			temp[targetTab] = "true";
			mui.extend(aniShow,temp);
			plus.webview.show(targetTab,"fade-in",300);
		}
		//隐藏当前;
		plus.webview.hide(activeTab);
		//更改当前活跃的选项卡
		activeTab = targetTab;
	});
	 //自定义事件，模拟点击“首页选项卡”
	document.addEventListener('gohome', function() {
		var defaultTab = document.getElementById("defaultTab");
		//模拟首页点击
		mui.trigger(defaultTab, 'tap');
		//切换选项卡高亮
		var current = document.querySelector(".mui-bar-tab>.mui-tab-item.mui-active");
		if (defaultTab !== current) {
			current.classList.remove('mui-active');
			defaultTab.classList.add('mui-active');
		}
	});
	//在android4.4.2中的swipe事件，需要preventDefault一下，否则触发不正常
	window.addEventListener('dragstart', function(e) {
		mui.gestures.touch.lockDirection = true; //锁定方向
		mui.gestures.touch.startDirection = e.detail.direction;
		console.log(e);
	});
	window.addEventListener('dragright', function(e) {
		if (!mui.isScrolling) {
			e.detail.gesture.preventDefault();
		}
	});
	 //监听右滑事件，若侧滑菜单未显示，右滑要显示菜单；
	window.addEventListener("swiperight", function(e) {
		//默认滑动角度在-45度到45度之间，都会触发右滑菜单，为避免误操作，可自定义限制滑动角度；
		if (Math.abs(e.detail.angle) < 4) {
			openMenu();
		}
	});
</script>
</body>
</html>